
from haystack import indexes
from crouse.models import CourseModel

class CourseIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=False)
    cname = indexes.CharField(model_attr="cname")
    intro = indexes.CharField(model_attr="intro")
    teacher = indexes.CharField(model_attr="teacher")
    id=indexes.IntegerField(model_attr="id")
    cover = indexes.CharField(model_attr="cover")
    price=indexes.DecimalField(model_attr="price")
    discount=indexes.DecimalField(model_attr="discount")
    level=indexes.CharField(model_attr="level")
    vedio=indexes.CharField(model_attr="vedio")
    ishot=indexes.BooleanField(model_attr="ishot")
    def get_model(self):
        return CourseModel

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

    def prepare_text(self, obj):
        return f"{obj.cname}{obj.intro}"
